package com.acwing.partition36;

import java.io.*;

/**
 * @author rkc
 * @date 2022/7/19 10:13
 */
public class AC3598二叉树遍历 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        while (true) {
            String pre = reader.readLine();
            if (pre == null || pre.isEmpty()) break;
            String in = reader.readLine();
            dfs(pre, in);
            writer.write("\n");
        }
        writer.flush();
    }

    private static void dfs(String pre, String in) throws IOException {
        if (pre.isEmpty()) return;
        char root = pre.charAt(0);
        int idx = in.indexOf(root);
        dfs(pre.substring(1, idx + 1), in.substring(0, idx));
        dfs(pre.substring(idx + 1), in.substring(idx + 1));
        writer.write(root);
    }
}
